﻿using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections;

namespace Framework.Common.LinqExtention
{
    /// <summary>
    /// 扩展分页
    /// </summary>
    public static class PagedListExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="index">第一页页码为0</param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IList<T> ToPagedList<T>(this IQueryable<T> query, int index, int pageSize)
        {
            index = Math.Max(0, index);
            return query.Skip(index * pageSize).Take(pageSize).ToList();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="index">第一页页码为0</param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IList<T> ToPagedList<T>(this IEnumerable<T> query, int index, int pageSize)
        {
            index = Math.Max(0, index);
            return query.Skip(index * pageSize).Take(pageSize).ToList();
        }

    }
}